from exceptiongroup import catch
import statistics

file_path = "./15/11081141.txt"
mobile_dict = {}
cost = []


def readFile():
    with open(file_path, 'r', encoding='utf-8') as f:
        for line in f:
            try:
                if line.startswith('start'):
                    ss = line.split(" ")
                    mobile_dict[ss[1]] = []
                    mobile_dict[ss[1]].append(ss[2].strip())
                elif line.startswith('searchAndEnterRoom'):
                    ss = line.split(" ")
                    mobile_dict[ss[1]].append(ss[2].strip())
                    cost.append(float(ss[2].strip()))
                elif line.startswith('end'):
                    ss = line.split(" ")
                    mobile_dict[ss[1]].append(ss[2].strip())
                    mobile_dict[ss[1]].append(float(ss[2].strip()) - float(mobile_dict[ss[1]][0]))

                else:
                    print(line)
            except:
                print(f"{line}日志数据格式有误")

def analysis():
    try:
        for key in mobile_dict:
            print(f"Key: {key}, Array: {mobile_dict[key]}")
        print(cost)
        # 计算最大值和最小值
        max_value = max(cost)
        min_value = min(cost)

        # 计算中位数
        median_value = statistics.median(cost)

        print(f"最大值: {max_value}")
        print(f"最小值: {min_value}")
        print(f"中位数: {median_value}")
    except:
        print(f"{key}日志数据格式有误")


if __name__ == '__main__':
    readFile()
    analysis()
